<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp" %>

<html>
<head>
    <title>优惠券管理</title>
    <script type="text/javascript" src="http://static.runoob.com/assets/qrcode/qrcode.min.js"></script>
    <meta name="decorator" content="default"/>
    <style>
        #wxzf {
            width: 100%;
            height: 100%;
            position: absolute;
            top: 0;
            left: 0;
            background-color: rgba(0, 0, 0, 0.2);
        }

        #wx {
            width: 300px;
            height: 300px;
            background-color: #e5e5e5;
            position: absolute;
            top: 0;
            left: 0;
            bottom: 0;
            right: 0;
            margin: auto;

        }

        #wx > label {
            border-bottom: 1px solid #ccc;
            width: 100%;
            height: 30px;
            line-height: 30px;
            text-indent: 2em;
        }

        #qrcode {
            width: 200px;
            margin: auto;
            margin-top: 20px;
        }

        #wx input {
            display: block;
            margin: auto;
            margin-top: 16px;
            text-align: center;
            margin-left: 20px;
        }

        /*.zf {
            width: 100%;
            overflow: hidden;

        }

        .zf > input {
            float: left;

        }*/
    </style>
    <script type="text/javascript">
        $(document).ready(function () {
            // reckon();
            $("#inputForm").validate({
                submitHandler: function (form) {
                    var flag = true;
                    if ($("#productId").val() == null || $("#productId").val() == "") {
                        flag = false;
                        alert("关联商品不能为空");
                    }
                    if ($("#discount").val() == null || $("#discount").val() == "") {
                        flag = false;
                        alert("优惠类型不能为空");
                    }

                    if ($("#stocks").val() == null || $("#stocks").val() == "") {
                        flag = false;
                        alert("发放数量不能为空");
                    }
                    if (flag) {
                        loading('正在提交，请稍等...');
                        form.submit();
                        /*$.ajax({
                            url: "\\${ctx}/shop/shop/hkShopCoupon/isIntegral",
                            type: "GET",
                            data: {
                                "integral": $("#integral").val()
                            },
                            success: function (res) {
                                if (res == "success") {
                                    loading('正在提交，请稍等...');
                                    form.submit();
                                } else {
                                    jBox.tip("乐币不足，请充值，5S后跳转到充值页面", "加载中");
                                    window.setTimeout(function () {
                                        document.getElementById("paya").click();
                                    }, 5000);
                                }
                            }
                        });*/
                    }
                },
                errorContainer: "#messageBox",
                errorPlacement: function (error, element) {
                    $("#messageBox").text("输入有误，请先更正。");
                    if (element.is(":checkbox") || element.is(":radio") || element.parent().is(".input-append")) {
                        error.appendTo(element.parent().parent());
                    } else {
                        error.insertAfter(element);
                    }
                }
            });

        });


        /*function reckon() {
            $.ajax({
                url: "\\${ctx}/shop/shop/hkShopCoupon/getReckonIntegral",
                type: "GET",
                data: {
                    "productId": $("#productId").val()
                },
                success: function (res) {
                    if (res != null) {
                        $("#integral").val(res);
                    }
                }
            });
        }*/

    </script>
</head>
<body>
<ul class="nav nav-tabs">
    <li><a href="${ctx}/shop/shop/hkShopCoupon/">优惠券列表</a></li>
    <li class="active"><a href="${ctx}/shop/shop/hkShopCoupon/form?id=${hkShopCoupon.id}">优惠券<shiro:hasPermission
            name="shop:shop:hkShopCoupon:edit">${not empty hkShopCoupon.id?'修改':'添加'}</shiro:hasPermission><shiro:lacksPermission
            name="shop:shop:hkShopCoupon:edit">查看</shiro:lacksPermission></a></li>
    <li style="display: none"><a id="paya" href="${ctx}/shop/shop/hkShopCoupon/goWXPay">充值</a></li>
</ul>
<br/>

<form:form id="inputForm" modelAttribute="hkShopCoupon" action="${ctx}/shop/shop/hkShopCoupon/save" method="post"
           class="form-horizontal">
    <form:hidden path="id"/>
    <form:hidden path="bisId" id="bisId" value="${hkShopCoupon.bisId}"/>
    <input type="hidden" id="orderNumber" value=""/>
    <sys:message content="${message}"/>

    <div class="control-group">

        <label class="control-label"><span style="color:red;">*&nbsp;</span>关联商品：</label>
        <div class="controls">
            <sys:tableSelect id="product" name="product.id" value="${hkShopCoupon.product.id}"
                             labelName="product.title" labelValue="${hkShopCoupon.product.title}" title="商品"
                             url="${ctx}/shop/product/hkShopProduct/list?1=1" checked="1"/>
            <br>
            <font style="color: red;">注：只能添加一款商品</font>
        </div>
    </div>

   <%-- <div class="control-group">
        <label class="control-label">支付乐币</label>
        <div class="controls">
            <form:input id="integral" path="integral" htmlEscape="false" maxlength="100" class="input-xlarge"
                        readonly="true"/>LB
            <br>
            <font style="color: red;">注：(自动计算)需支付相应乐币，优惠券方能发布成功。</font>
        </div>
    </div>--%>
    <div class="control-group">
        <label class="control-label"><span style="color:red;">*&nbsp;</span>优惠券名称：</label>
        <div class="controls">
            <form:input path="title" htmlEscape="false" maxlength="200" class="input-xlarge"/>
        </div>
    </div>
    <div class="control-group">
        <label class="control-label"><span style="color: red;">&nbsp;*</span>优惠类型：</label>
        <c:if test="${not empty hkShopCoupon.id}">
            <div class="controls">
                折扣券
                <form:input id="discount" value="9.9" path="discount" htmlEscape="false" cssStyle="width: 15%;"
                            class="input-xlarge required"
                            t_value="" o_value=""
                            onblur="if(!this.value.match(/^((0\.[1-9]{1,2})|(([1-9]{1})(\.\d{1,2})?))$/))this.value=this.o_value;else{if(this.value.match(/^\.\d+$/))this.value=0+this.value;if(this.value.match(/^\.$/))this.value=0;this.o_value=this.value}"/>折
                <br>
                <font style="color: red;">注：只能填写大于0.1且保留两位小数的值。</font>
            </div>
        </c:if>
        <c:if test="${empty hkShopCoupon.id}">
            <div class="controls">
                <form:input id="discount" value="9.9" path="discount" htmlEscape="false" cssStyle="width: 15%;"
                            class="input-xlarge required"
                            t_value="" o_value=""
                            onblur="if(!this.value.match(/^((0\.[1-9]{1,2})|(([1-9]{1})(\.\d{1,2})?))$/))this.value=this.o_value;else{if(this.value.match(/^\.\d+$/))this.value=0+this.value;if(this.value.match(/^\.$/))this.value=0;this.o_value=this.value}"/>折
                <font style="color: red;">注：只能填写大于0.1且保留两位小数的值。</font>
            </div>
        </c:if>
    </div>
    <div class="control-group">
        <label class="control-label"><span style="color:red;">*&nbsp;</span>发放数量：</label>
        <div class="controls">
            <form:input id="stocks" path="stocks" htmlEscape="false" maxlength="11"
                        class="input-xlarge digits  required"/>
        </div>
    </div>
    <div class="control-group">
        <label class="control-label"><span style="color:red;">*&nbsp;</span>有效开始时间：</label>
        <div class="controls">
            <input name="beginTime" type="text" readonly="readonly" maxlength="20" class="input-medium Wdate "
                   value="<fmt:formatDate value="${hkShopCoupon.beginTime}" pattern="yyyy-MM-dd HH:mm:ss"/>"
                   onclick="WdatePicker({dateFmt:'yyyy-MM-dd',isShowClear:false});"/>
        </div>
    </div>
    <div class="control-group">
        <label class="control-label"><span style="color:red;">*&nbsp;</span>有效结束时间：</label>
        <div class="controls">
            <input name="endTime" type="text" readonly="readonly" maxlength="20" class="input-medium Wdate "
                   value="<fmt:formatDate value="${hkShopCoupon.endTime}" pattern="yyyy-MM-dd HH:mm:ss"/>"
                   onclick="WdatePicker({dateFmt:'yyyy-MM-dd',isShowClear:false});"/>
        </div>
    </div>
    <div class="form-actions">
        <c:if test="${empty hkShopCoupon.id}">
            <shiro:hasPermission name="shop:shop:hkShopCoupon:edit"><input id="btnSubmit" class="btn btn-primary"
                                                                           type="submit"
                                                                           value="保 存"/>&nbsp;</shiro:hasPermission>
        </c:if>
        <input id="btnCancel" class="btn" type="button" value="返 回" onclick="history.go(-1)"/>


    </div>
</form:form>
</body>
</html>